package com.aisile.yongyouyun;

import com.alibaba.fastjson.JSON;
import org.apache.poi.ss.formula.functions.T;
import org.junit.Test;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

/**
 * @Auther:yry
 * @Date:2023/12/27 0027
 * @VERSON:1.0
 */
public class ResttemplateTestDemo {


    @Test
    public void matchIdentityTest(){

        RestTemplate restTemplate = new RestTemplate();
        String url ="https://api.yonyoucloud.com/apis/dst/matchIdentity/matchIdentity";//请求接口地址

        Map params = new HashMap();
        params.put("idNumber", "210103195103222113");
        params.put("userName", "王东镇");

        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.add("apicode", "3c77eeb72485401785d82e1d86c09a27");//APICODE
        httpHeaders.add("Content-Type", "application/json");
        HttpEntity<String> httpEntity = new HttpEntity<>(JSON.toJSONString(params),httpHeaders);

        ResponseEntity<String> responseEntity = restTemplate.postForEntity(url,httpEntity,String.class);
        Map map =  JSON.parseObject(responseEntity.getBody(),Map.class);
        System.out.println(responseEntity);
        System.out.println(((Integer)map.get("code")) == 400100);

    }

    @Test
    public void IdcardOCRTest(){
//        RestTemplate restTemplate = new RestTemplate();
//        String url ="https://api.yonyoucloud.com/apis/dst/IdcardOCR/IdcardOCR";
//
//        Map<String, Object> params = new HashMap<String, Object>();//请求参数
//        params.put("image", "https://hmtt122.oss-cn-shanghai.aliyuncs.com/demo_idcard.png");
//        params.put("ocrType", "0");
//        params.put("imageType", "URL");
//
//
//        HttpHeaders httpHeaders = new HttpHeaders();
//        httpHeaders.add("apicode","61577c25a7dc40c68e6ee92b1e6c34a5");
//        httpHeaders.add("Content-Type", "application/json;charset=utf-8");
//
//        //@Nullable T body, @Nullable MultiValueMap<String, String> headers
//
//        HttpEntity<String> entity = new HttpEntity<>(JSON.toJSONString(params),httpHeaders);
//
//        ResponseEntity<String> responseEntity =  restTemplate.postForEntity(url,entity,String.class);
//
//        System.out.println(responseEntity);
//        System.out.println(responseEntity.getBody());
       // Map map =  JSON.parseObject(responseEntity.getBody(),Map.class);
        Map map = JSON.parseObject(
                "{\"message\":\"成功\",\"data\":{\"tradeNo\":\"1189233948824174592\",\"code\":\"0\",\"riskType\":\"normal\",\"address\":\"沈阳市东陵区文化东路24-8号1-3-6\",\"birth\":\"19510322\",\"name\":\"王东镇\",\"cardNum\":\"210103195103222113\",\"sex\":\"男\",\"nation\":\"汉\",\"issuingDate\":\"\",\"issuingAuthority\":\"\",\"expiryDate\":\"\"},\"code\":\"601200000\"}"
                ,Map.class);
        Map data = (Map) map.get("data");
        System.out.println("姓名："+data.get("name"));
        System.out.println("身份证号码："+data.get("cardNum"));
        System.out.println(data);


    }


    @Test
    public void htjc(){
        RestTemplate restTemplate = new RestTemplate();
        String url ="https://api.yonyoucloud.com/apis/dst/Biologicalexamination/Biologicalexamination";//请求接口地址
        Map<String, Object> params = new HashMap<String, Object>();//请求参数
        params.put("image", "https://hmtt122.oss-cn-shanghai.aliyuncs.com/demo_idcard.png");
        params.put("imageType", "URL");

        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.add("apicode", "5af21f6af3724453b4067b4fce3a8e61");//APICODE
        httpHeaders.add("Content-Type", "application/json");
        HttpEntity<String> httpEntity = new HttpEntity<>(JSON.toJSONString(params), httpHeaders);

        ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, httpEntity, String.class);
        System.out.println(responseEntity.getBody());
        String success = "{\"message\":\"成功\",\"data\":{\"checkStatus\":\"0\",\"score\":\"0\",\"tradeNo\":\"1189570897578455040\",\"remark\":\"检测成功\",\"code\":\"0\"},\"code\":\"601200000\"}";
        Map map = JSON.parseObject(responseEntity.getBody(), Map.class);
        // {code=601200000, data={"score":"84","checkStatus":"0","code":"0","tradeNo":"1189569884804763648","remark":"检测成功"}, message=成功}
        // {code=601200000, data={"score":"0","checkStatus":"0","code":"0","tradeNo":"1189570101817782272","remark":"检测成功"}, message=成功}
        // {code=601200000, data={"score":"0","checkStatus":"0","code":"0","tradeNo":"1189570312304463872","remark":"检测成功"}, message=成功}
        System.out.println(map);
    }

}
